import Vue from 'vue'
import VueRouter from 'vue-router'
import FirstPage from "@/views/FirstPage"
import News from "@/views/News"
import Sports from "@/views/Sports"
import HomePage from "@/views/children/HomePage"
import Demostic from "@/views/children/Demostic"
import Abroad from "@/views/children/Abroad"
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/FirstPage'
  },
  {
    path: '/firstpage',
    component: FirstPage,
  },
  {
    path: '/news',
    component: News,
  },
  {
    path: '/sports',
    component: Sports,
    children: [
      {
        path: '/sports',
        redirect: '/sports/demostic'
      },
      {
        path: 'homepage',
        component: HomePage,
      },
      {
        path: 'demostic',
        component: Demostic,
      },
      {
        path: 'abroad',
        component: Abroad,
      }
    ]
  },

]

const router = new VueRouter({
  routes
})

const isLogin = true
router.beforeEach((to, from, next) => {
  if (to.path === FirstPage && !isLogin) {
    alert('请登录')
    next(false)
  } else {
    next(true)
  }
})

export default router
